package com.maycur.ctrip.service;


import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

public interface RedisService {
    /**
     * WARNING: This method will clear redis current database data!
     */
    void flushDB();

    /**
     * 通过正则匹配keys
     *
     * @param pattern
     * @return
     */
    Set<String> setKeys(String pattern);

    /**
     * 检查是否连接成功
     *
     * @return
     */
    String ping();

    boolean exists(String key);

    void saveValueWithExpireTime(byte[] key, byte[] value, long expireTime);

    void saveValue(byte[] key, byte[] value);

    void saveValue(final String key, final String value);

    void saveValueWithExpireTime(String key, String value, long expireTime, TimeUnit timeUnit);

    String getValue(final String key);

    <T> void saveGeneric(final String key, final T value);

    <T> void saveGenericWithExpireTime(String key, T obj, long expireTime, TimeUnit timeUnit);

    <T> T getGeneric(String key, Class<T> valueClass);

    <T> void saveGenericList(final String key, final List<T> list, final Class<T> clazz);

    <T> void saveGenericListWithExpireTime(String key, List<T> list, Class<T> clazz, long expireTime, TimeUnit timeUnit);

    <T> List<T> getGenericList(final String key, final Class<T> clazz);

    <T> void saveJsonGenericList(final String key, final List<T> list);

    <T> void saveJsonGenericListWithExpireTime(final String key, final List<T> list, long expireTime, TimeUnit timeUnit);

    <T> List<T>  getJsonGenericList(final String key, final Class<T> clazz);

    void remove(String key);

    void mRemove(String... keys);

    void hSaveValueWithExpireTime(byte[] key, byte[] field, byte[] value, long expireTime);

    void hSaveValue(byte[] key, byte[] field, byte[] value);

    void hSaveValue(String key, String field, String value);

    void hSaveValueWithExpireTime(String key, String field, String value, long expireTime, TimeUnit timeUnit);

    String hGetValue(String key, String field);

    <T> void hSaveGenericWithExpireTime(String key, String field, T value, long expireTime);

    <T> void hSaveGeneric(String key, String field, T value);

    <T> T hGetGeneric(final String key, final String field, final Class<T> clazz);

    <T> void hSaveJsonGenericListWithExpireTime(String key, String field, List<T> list, long expireTime);

    <T> void hSaveJsonGenericList(String key, String field, List<T> list);

    <T> List<T> hGetJsonGenericList(final String key, final String field, final Class<T> clazz);

    void hRemove(final String key, final String field);

    void hmRemove(String key, String... fields);

    /**
     * 从redis中获取对象field and field's value map列表
     *
     * @param key
     * @return
     */
    Map hGetAllByKey(final String key);





}
